home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Idling / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  3.8 KB  |  148 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef FRAME_H
  10. #include "Frame.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"
  15. #endif
  16.  
  17. #ifndef BINDING_K
  18. #include "Binding.k"
  19. #endif
  20.  
  21. // ----- Framework Includes -----
  22. #ifndef FWABOUT_H
  23. #include "FWAbout.h"    //::FW_About()
  24. #endif
  25.  
  26. #ifndef FWITERS_H
  27. #include "FWIters.h"    // FW_CPresentationFrameIterator, FW_CFrameFacetIterator
  28. #endif
  29.  
  30. #ifndef FWIDLE_H
  31. #include "FWIdle.h"        // FW_CIdler
  32. #endif
  33.  
  34. #ifndef SLMIXOS_H
  35. #include "SLMixOS.h"    // FW_GetMainScreenBounds
  36. #endif
  37.  
  38. //==============================================================================
  39. #ifdef FW_BUILD_MAC
  40. #pragma segment Idling
  41. #endif
  42.  
  43. FW_DEFINE_AUTO(CIdlingPart)
  44. //==============================================================================
  45. CIdlingPart::CIdlingPart(ODPart* odPart)
  46.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  47.       fIdlingActive(TRUE),
  48.       fIdler(NULL),
  49.       fPresentation(NULL)
  50. {
  51.     FW_END_CONSTRUCTOR
  52. }
  53.  
  54. //--------------------------------------------------------------------------------
  55. CIdlingPart::~CIdlingPart()
  56. {
  57.     FW_START_DESTRUCTOR
  58.     delete fIdler;
  59. }
  60.  
  61. //--------------------------------------------------------------------------------
  62. void 
  63. CIdlingPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)    // Override
  64. {
  65.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  66.     FW_CSelection* selection = NULL;
  67.     const ODType kMainPresentation = "Apple:Presentation:Idling";
  68.     fPresentation = this->RegisterPresentation(ev, kMainPresentation, TRUE, selection);
  69.     const ODIdleFrequency kIdleFreq = 10;    // ticks
  70.     fIdler = FW_NEW(FW_CIdler, (this, kIdleFreq));
  71.     fIdler->RegisterIdle(ev);
  72. }
  73.  
  74. //--------------------------------------------------------------------------------
  75. FW_CFrame* 
  76. CIdlingPart::NewFrame(Environment* ev, ODFrame* odFrame,
  77.                         FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  78. {
  79.     FW_UNUSED(fromStorage);
  80.     return FW_NEW(CIdlingFrame, (ev, odFrame, presentation, this));
  81. }
  82.  
  83. //--------------------------------------------------------------------------------
  84. FW_CContent* 
  85. CIdlingPart::NewPartContent(Environment* ev)
  86. {
  87.     FW_UNUSED(ev);
  88.     return NULL;
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. FW_CWindow* 
  93. CIdlingPart::NewDocumentWindow(Environment* ev)
  94. {    
  95.     FW_CRect screenBounds;
  96.     ::FW_GetMainScreenBounds(screenBounds);
  97.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  98.     
  99.     return new FW_CWindow(ev,
  100.                         this,
  101.                          FW_CPart::fgViewAsFrameToken,
  102.                         fPresentation,
  103.                         FW_CPoint(FW_IntToFixed(72), FW_IntToFixed(72)),
  104.                         screenBounds.TopLeft(),
  105.                         FW_kDocumentWindow);
  106. }
  107.  
  108. //--------------------------------------------------------------------------------
  109. FW_Handled 
  110. CIdlingPart::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)    // Override
  111. {
  112.     FW_UNUSED(theNullEvent);
  113.     FW_CPresentationFrameIterator iter(ev, fPresentation);
  114.     for (CIdlingFrame* frame = (CIdlingFrame*)iter.First(ev);
  115.         iter.IsNotComplete(ev);
  116.         frame = (CIdlingFrame*)iter.Next(ev)) 
  117.         {
  118.             FW_CFrameFacetIterator facetIter(ev, frame);                
  119.             for (ODFacet* facet = facetIter.First(ev);
  120.                 facetIter.IsNotComplete(ev);
  121.                 facet = facetIter.Next(ev)) 
  122.                 {
  123.                     frame->MyToggleColor();
  124.                     frame->Draw(ev, facet, NULL);
  125.                 }    // for facets
  126.         }    // for frames
  127.     return true;
  128. }
  129.  
  130. //--------------------------------------------------------------------------------
  131. void 
  132. CIdlingPart::MyToggleIdling(Environment* ev)
  133. {
  134.     fIdlingActive = ! fIdlingActive;
  135.     fIdler->RegisterIdle(ev, fIdlingActive);
  136. }
  137.  
  138. //--------------------------------------------------------------------------------
  139. FW_Handled 
  140. CIdlingPart::DoAbout(Environment* ev)    // Override
  141. {
  142.     ::FW_About(ev, this, kAbout);
  143.     
  144.     return FW_kHandled;
  145. }
  146.  
  147.  
  148.